import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../model/cartmodellist.dart';
class CatePage extends StatefulWidget {
  CatePage({Key key}) : super(key: key);

  @override
  _CatePageState createState() => _CatePageState();
}

class _CatePageState extends State<CatePage> {
  @override
  void initState(){
    getlist();
   // add(1);
   // print('没有数据吗${m1}');
  }
  List<Map> goods = [
    {"id": 1, "name": "衣物","flag":false},
    {"id": 2, "name": "女士","flag":false},
    {"id": 3, "name": "内衣","flag":false},
    {"id": 4, "name": "美食","flag":false},
    {"id": 5, "name": "鞋子","flag":false},
    {"id": 6, "name": "箱包","flag":false},
    {"id": 7, "name": "手机","flag":false},
    {"id": 9, "name": "数码家电","flag":false},
    {"id": 10, "name": "医药","flag":false},
    {"id": 12, "name": "口红","flag":false},
    {"id": 11, "name": "日用","flag":false}
    
  ];
  int count;
  Widget _goods(BuildContext context, int index) {
    bool flag = false;
    return InkWell(
      onTap: () {
        setState(() {
          flag = true;
          count = goods[index]['id'];
         add(goods[index]['id']);
          this._goodslist(context, index, );
          goods.forEach((item) {
            if(item['id']==goods[index]['id']){
              item['flag']=true;
            }else{
              item['flag']=false;
            }
          });
        });
      },
      child: Container(
        height: 60,
         width: 100,
        decoration: BoxDecoration(
          //border: Border(

          border: Border(
            top: BorderSide(width: 1, color: Colors.black26),
            left: BorderSide(width: 1, color: Colors.black26),
            right: BorderSide(width: 1, color: Colors.black26),
          ),
          //bottom: BorderSide(
          //   width: 1, color: Colors.black38),

          //  ),
        ),
        child: Center(
          child: Text(
            '${goods[index]['name']}',
            style: TextStyle(
                fontSize: 16, color: goods[index]['flag'] ? Colors.red : Colors.black45),
          ),
        ),
      ),
    );
  }

  Widget _goodslist(BuildContext context, int index,) {
   // print('哇没有变化吗${m1}');
     final ValueNotifier<List> _counter = ValueNotifier<List>([]);
   return 
ValueListenableBuilder(
  valueListenable: _counter,
child: null,
 builder: (BuildContext context,value,Widget child){
   return    InkWell(
     onTap: (){
  Navigator.of(context).pushNamed('/goodscommodity',arguments: {"id":m1[index]});
     },
     child: Card(
     child: Row(
       mainAxisAlignment: MainAxisAlignment.start,
       crossAxisAlignment: CrossAxisAlignment.start,
       children: <Widget>[
        Container(
          width: ScreenUtil().setWidth(200),
          height: 100,
         // child: Image.network('http://dbyxs.xyz:3005/uploads/78b7ea1a750505de7e4150a5d9eb9666',fit:BoxFit.cover),
          child:  Image.network('${m1[index]['url'].split(',')[0]}',fit: BoxFit.cover,),
        ),
        Container(
          padding: EdgeInsets.fromLTRB(5, 10, 5, 5),
          width: ScreenUtil().setWidth(350),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text('${m1[index]['goodsname']}', maxLines: 2, overflow: TextOverflow.ellipsis, ),
            SizedBox(height:10),
            Text('价格 ${m1[index]['price']}',style: TextStyle(color:Colors.redAccent),),
             SizedBox(height:15),
            Text('已有${m1[index]['price']-30}人购买',style:TextStyle(color:Colors.grey,fontSize: 12))
          ],
        ),
        )
       ],
     ),
   ),
   );
});

  }

  @override
  Widget build(BuildContext context) {
    //add(1);
    return Scaffold(
        appBar: AppBar(
          title: Text('分类'),
        ),
        
        body: Container(
          child: Row(
            children: <Widget>[
              Container(
                width: ScreenUtil().setWidth(140),
                child: ListView.builder(
                  itemBuilder: _goods,
                  itemCount: goods.length,
                ),
              ),
              Container(
                width: ScreenUtil().setWidth(610),
                child: ListView.builder(itemBuilder: _goodslist,itemCount:m1.length),
              )
            ],
          ),
        ));
  }
}
// class Tion extends StatelessWidget {
//   const Tion({Key key}) : super(key: key);

//   @override
//   Widget build(BuildContext context) {
//     return Container(
//       child:
//      Text('我是列表页')
//       ,
//     );
//   }
// }
